package dev.nextcore.config

import org.springframework.ai.chat.client.ChatClient
import org.springframework.ai.chat.model.ChatModel
import org.springframework.ai.openai.api.OpenAiApi
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary


@Configuration
class AiConfig {
    @Bean
    @Primary  // 表示这是首选的 ChatModel，当有多个时优先使用它
    fun openAiChatModel(): OpenAiApi.ChatModel {
        return ChatModelFactory.createChatModel(OpenAiChatModelConfig.builder()
            .apiKey("your-openai-api-key")
            .baseUrl("https://api.openai.com/v1")
            .build())
    }

    @Bean
    fun ollamaChatModel(): ChatModel {
        return ChatModelFactory.createChatModel(OllamaChatModelConfig.builder()
            .baseUrl("http://localhost:11434")  // Ollama 默认地址
            .modelName("llama2")               // 模型名称
            .build())
    }
}